import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: () => import('@/components/layout/index.vue'),
      children: [
        {
          path: '',
          name: 'home-index',
          component: () => import('@/views/home/index.vue'),
        },
        {
          path: '/direct',
          name: 'direct',
          component: () => import('@/views/direct/index.vue'),
        },
      ],
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login/index.vue'),
    },
    {
      path: '/404',
      name: '404',
      component: () => import('@/views/error/404.vue'),
    },
  ],
})

router.beforeEach((to, from) => {
  console.log('🚀 ~ router.beforeEach ~ to:', to.matched)
  if (to.matched.length) {
    return true
  } else {
    return '/404'
  }
})

export default router
